<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* body{
            position: relative;height: 100%;
        } */
        #div{
            width: 100px;height: 100px;background-color: palegoldenrod;position: absolute;
        }
        .test{
            height: 20000px;
        }
    </style>
</head>
<body>
    <div id="div"></div>
    <div class="test"></div>
    <script>
        // 13. 顶部悬浮
        // - 使用js模拟position:fixed
        var div = document.getElementById('div')
        // document.onclick = function(){
        //     div.top = 1000
        //     console.log('===>',div.scrollTop)
        // }
        window.onscroll = function(){
            div.style.marginTop = document.documentElement.scrollTop + 500 + 'px'
            console.log(div.scrollTop,document.documentElement.scrollTop)
        }
    </script>
</body>
</html>